﻿using Oracle.ManagedDataAccess.Client;
using System;
using System.Data;
using ZLSoft.ZLDocEditorEvents.Comm;

namespace ZLSoft.ZLDocEditorEvents
{
    internal class DBHelper
    {
        #region 启动事务批量执行Sql语句（用于增、删、改数据）

        /// <summary>
        /// 启动事务批量执行Sql语句（用于增、删、改数据）
        /// </summary>
        /// <param name="strSqlList">Sql语句列表</param>
        /// <param name="cmdParas">对应Sql的参数值列表</param>
        internal static void ExecuteSqlTran(string sql, CommandType type)
        {
            using (OracleConnection dbConn = new OracleConnection(Init.Conn))
            {
                if (dbConn.State == ConnectionState.Closed)
                {
                    dbConn.Open();
                }
                using (OracleTransaction trans = dbConn.BeginTransaction())
                {
                    try
                    {
                        using (OracleCommand cmd = new OracleCommand())
                        {

                            cmd.Connection = dbConn;
                            cmd.CommandText = sql;
                            cmd.Transaction = trans;
                            cmd.CommandType = type;
                            int i=cmd.ExecuteNonQuery();
                            trans.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw ex;
                    }
                    finally
                    {
                        dbConn.Close();
                    }
                }
            }
        }

        #endregion
    }
}
